<?php
/**
 * Created by PhpStorm.
 * User: ndong
 * Date: 2016/5/23
 * Time: 10:54
 */

namespace App\Http\Controllers\Site;

use App\Category;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Job;
use Illuminate\Http\Request;

class BusinessController extends Controller
{
    public function getIndex($id = 0)
    {
        if (0 == $id) {
            abort(404);
        } else {
            $father = Category::where('categoryid', $id)->first();
            if (isset($father->parentid) && 0 != $father->parentid) {
                if ("business" == config('site.jump')[$father->parentid]) {
                    $lists = Job::where('categoryid', $id)->where('state', '已发布')->paginate(config('site.pageSize'));
                    return view('site.business.index', [
                        'lists' => $lists,
                        'fatherId' => $father->parentid,
                        'id' => "",
                    ]);
                } else {
                    abort(404);
                }
            } else {
                $lists = Job::where('parentcategory',$id)->where('state', '已发布')->paginate(config('site.pageSize'));
                return view('site.business.index', [
                    'lists' => $lists,
                    'fatherId' => $id,
                    'id' => $id,
                ]);
            }
        }
    }

    //查找具体项
    public function getDetail($jobid)
    {
        $business = Job::find($jobid);
        if ("" == $business) {
            abort(404);
        }
        return view('site.business.detail', [
            'business' => $business,
            'cate' => $jobid
        ]);
    }
}